package com.ztc.ZtcTransportPercentageScale.dao;


import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcTransportPercentageScale.bean.ZtcTransportPercentageScale;
import org.springframework.stereotype.Repository;
import javax.persistence.Query;
import java.util.List;

/**
 * @author 2017/11/19
 */
@Repository("ZtcTransportPercentageScaleDao")
public class ZtcTransportPercentageScaleDao extends BaseDaoImpl<ZtcTransportPercentageScale> {

    public String update(ZtcTransportPercentageScale ztcTransportPercentageScale) {
        this.getHibernateTemplate().merge(ztcTransportPercentageScale);
        return ztcTransportPercentageScale.getId();
    }

    /**
     * 获取当前公司旗下公司提成比例信息
     * @param cid  公司ID
     * @return
     */
    public List<Object[]> getPercentageScaleInfo(String cid){
        String sql="select s.id ,s.full_name ,s.`type`,t.income_scale,ifnull(t.create_time,''),ifnull(t.modify_transport_name,''),ifnull(t.modify_username,''),ifnull(t.modify_time,''),ifnull(t.modify_remark,'') from ztc_transport z,ztc_transport s,ztc_transport_percentage_scale t where z.id=s.parent_id and s.id=t.transport_id and z.id='"+cid+"' and s.`status`=3 and s.type<>5 ";
        Query query=this.currentSession().createNativeQuery(sql);
        return  query.getResultList();
    }
    /**
     * 查询公司提成收益比例
     * @param transportId 公司ID
     */
    public ZtcTransportPercentageScale getTransportPercentageScaleByTransportId(String transportId){
        return this.findUniqueBy("transportId",transportId);
    }
}
